package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.view.View;

import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityRecResultBinding;

public class RecResultActivity extends BaseAc<ActivityRecResultBinding> {

    public static String sResult;
    private int textSize = 16;

    @Override
    protected int onCreate() {
        return R.layout.activity_rec_result;
    }

    @Override
    protected void initView() {
        mDataBinding.ivPatternTextBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvTextSizeAdd.setOnClickListener(this);
        mDataBinding.tvTextSizeMinus.setOnClickListener(this);
        mDataBinding.tvCopy.setOnClickListener(this);
        mDataBinding.tvTranslate.setOnClickListener(this);

        mDataBinding.etRecResult.setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvTextSizeAdd://字号+
                textSize++;
                mDataBinding.etRecResult.setTextSize(textSize);
                break;
            case R.id.tvTextSizeMinus://字号-
                if (textSize == 1) {
                    ToastUtils.showShort(getString(R.string.text_size_min));
                    return;
                }
                textSize--;
                mDataBinding.etRecResult.setTextSize(textSize);
                break;
            case R.id.tvCopy://复制
                if (TextUtils.isEmpty(mDataBinding.etRecResult.getText().toString().trim())) {
                    ToastUtils.showShort(R.string.no_content_copy_tips);
                } else {
                    ClipboardUtils.copyText(mDataBinding.etRecResult.getText().toString().trim());
                    ToastUtils.showShort(getString(R.string.copy_success_tips));
                }
                break;
            case R.id.tvTranslate://翻译
                TranslateActivity.sResult = mDataBinding.etRecResult.getText().toString();
                startActivity(TranslateActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        mDataBinding.etRecResult.setText(sResult);
    }
}